import 'package:flutter/material.dart';

// 自定义图片文本按钮
class CustomImageTextButton extends StatelessWidget {
  final Widget image; // 图片Widget（更灵活，可以是AssetImage、NetworkImage等）
  final String text; // 按钮文本
  final double imageHeight;
  final double imageWidth;
  final double spacing;
  final VoidCallback? onTap;
  final TextStyle? textStyle;
  final Color? splashColor;
  final EdgeInsetsGeometry? padding;
  final Color? backgroundColor;
  final double borderRadius;
  final BoxBorder? border;
  final List<BoxShadow>? shadow;
  final bool enabled; // 是否启用按钮

  const CustomImageTextButton({
    Key? key,
    required this.image,
    required this.text,
    this.imageHeight = 40,
    this.imageWidth = 40,
    this.spacing = 8,
    this.onTap,
    this.textStyle,
    this.splashColor,
    this.padding,
    this.backgroundColor,
    this.borderRadius = 8,
    this.border,
    this.shadow,
    this.enabled = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: enabled ? onTap : null,
      splashColor: splashColor ?? Theme.of(context).splashColor,
      borderRadius: BorderRadius.circular(borderRadius),
      child: Container(
        padding: padding ?? const EdgeInsets.all(12),
        decoration: BoxDecoration(
          color: backgroundColor,
          borderRadius: BorderRadius.circular(borderRadius),
          border: border,
          boxShadow: shadow,
        ),
        child: Opacity(
          opacity: enabled ? 1.0 : 0.5,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              SizedBox(
                height: imageHeight,
                width: imageWidth,
                child: image,
              ),
              SizedBox(height: spacing),
              Text(
                text,
                textAlign: TextAlign.center,
                style: textStyle ??
                    Theme.of(context).textTheme.labelLarge?.copyWith(
                          color: enabled
                              ? Theme.of(context).textTheme.labelLarge?.color
                              : Theme.of(context).disabledColor,
                        ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
